//
//  MainTopicScrollView.m
//  ZITHER
//
//  Created by 吴凡 on 2019/2/14.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "MainTopicScrollView.h"
#import "MainTopicViewController.h"

@implementation MainTopicScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
        [self setUI];
    }
    return self;
}

-(void)defaultConfiguration{
    self.bounces = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.bounces = NO; // 默认为YES 取消设置NO
    // 当bounces属性为NO时，以下两个属性设置无效
    self.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
    self.alwaysBounceVertical = YES; // 垂直方向弹簧效果
    self.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
    self.backgroundColor = [UIColor whiteColor];
    self.pagingEnabled = YES;
    self.contentSize = CGSizeMake(kScreenW*2,0);
    self.delegate = self;
}


-(void)setUI{
    [self addSubview:self.topicTableView];
    [self addSubview:self.userTableView];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (scrollView.contentOffset.x == 0) {
        [self changePage:0];
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH){
        [self changePage:1];
    }
}

-(void)changePage:(int)index{
    MainTopicViewController *vc  = (MainTopicViewController*)[self getViewController:[MainTopicViewController class]];
    [UIView animateWithDuration:0.2 animations:^{
        CGFloat width = [NSString textWidth:@"话题" font:14 height:15];
        CGRect rect = self.frame;//付值
        if (index ==0) {
            rect = CGRectMake(vc.baseNavigationView.NavViewStyleMyInterest.leftTitleBtn.frame.origin.x+25, NaviHeight-2,width,2);
        }else{
            rect = CGRectMake(vc.baseNavigationView.NavViewStyleMyInterest.rightTitleBtn.frame.origin.x+25, NaviHeight-2,width,2);
        }
        vc.baseNavigationView.NavViewStyleMyInterest.viewBlcak.frame = rect;

    }];
}

- (MainTopicTableView *)topicTableView{
    if (!_topicTableView) {
        _topicTableView = [[MainTopicTableView alloc]initializeFrame:CGRectMake(0, 0, kScreenW,self.frame.size.height) isMj:0 isEstimatedRowHeight:YES addRegisterNib:@[@"MainTopicContentCell",@"MainTopicSingleImageCell",@"MainTopicMulImageCell",@"MainTopicShortCell",@"MainTopicExprieCellTableViewCell"]];
    }
    return _topicTableView;
}
- (WX_UserTableView *)userTableView{
    if (!_userTableView) {
        _userTableView = [[WX_UserTableView alloc]initWithFrame:CGRectMake(kScreenW, 0, kScreenW, self.frame.size.height)];
        _userTableView.indexType = @"2";
    }
    return _userTableView;
}
@end
